import ReactAce from 'react-ace-editor';
import React, { Component } from 'react';
import { Icon } from 'antd';
import './index.less';
import store from '../../../redux/index';

class CodeEditor extends Component {
  constructor(props) {
    super(props);
    this.state = {
      setReadOnly: true,
    };
  }
  onChange(newValue, e) {
    // console.log(newValue, e);
    // const editor = this.ace.editor; // The editor object is from Ace's API
    // console.log(editor.getValue()); // Outputs the value of the editor
  }
  Return = () => {
    store.dispatch({ type: 'SetCodeOff', SetCodeOff: false });
    document.getElementsByTagName('body')[0].className = document.getElementsByTagName('html')[0].className = '';
  }
  render() {
    return (
      <div>
        <span className="Return" onClick={this.Return}><Icon type="rollback" />返回</span>
        <ReactAce
          mode="golang"
          theme="twilight"
          setReadOnly={this.state.setReadOnly}
          setValue={this.props.result}
          onChange={this.onChange}
          style={{ height: document.documentElement.clientHeight || document.body.clientHeight + 'px', width: document.documentElement.clientWidth || document.body.clientWidth + 'px' }}
          // ref={instance => { this.ace = instance; }} // Let's put things into scope
        />
      </div>
    );
  }
}
export default CodeEditor;